package config

import (
	"fmt"
	"github.com/spf13/viper"
)

var (
	GlobalConfig Config
)

func init() {
	GlobalConfig = Load()
}

type Config struct {
	Server  *server
	Request *request
}

type server struct {
	Host string
	Port int
	Log  bool
}

type request struct {
	Url        string
	OperatorId string
}

func Load() (cfg Config) {
	viper.SetConfigName("config")
	viper.SetConfigType("yaml")
	viper.AddConfigPath("config")
	err := viper.ReadInConfig()
	if err != nil {
		panic(fmt.Errorf("fatal error config file: %w", err))
	}
	err = viper.Unmarshal(&cfg)
	if err != nil {
		panic(err)
	}
	return
}
